f=open('pinout_fmc_hpc.txt')
lines=f.readlines()
f.close()
for i in range(len(lines)):
	rowname_A='A'
	index_A=10
	if lines[i].split()[index_A]!='GND':
		line=[rowname_A+lines[i].split()[0],lines[i].split()[index_A]]
		with open('fmc_row'+rowname_A+'.txt','aw') as ff:
			ff.write(' '.join(line)+'\n')

for i in range(len(lines)):
	rowname_B='B'
	index_B=9
	if lines[i].split()[index_B]!='GND':
		line=[rowname_B+lines[i].split()[0],lines[i].split()[index_B]]
		with open('fmc_row'+rowname_B+'.txt','aw') as ff:
			ff.write(' '.join(line)+'\n')

for i in range(len(lines)):
	rowname_C='C'
	index_C=8
	if lines[i].split()[index_C]!='GND':
		line=[rowname_C+lines[i].split()[0],lines[i].split()[index_C]]
		with open('fmc_row'+rowname_C+'.txt','aw') as ff:
			ff.write(' '.join(line)+'\n')

for i in range(len(lines)):
	rowname_D='D'
	index_D=7
	if lines[i].split()[index_D]!='GND':
		line=[rowname_D+lines[i].split()[0],lines[i].split()[index_D]]
		with open('fmc_row'+rowname_D+'.txt','aw') as ff:
			ff.write(' '.join(line)+'\n')

for i in range(len(lines)):
	rowname_E='E'
	index_E=6
	if lines[i].split()[index_E]!='GND':
		line=[rowname_E+lines[i].split()[0],lines[i].split()[index_E]]
		with open('fmc_row'+rowname_E+'.txt','aw') as ff:
			ff.write(' '.join(line)+'\n')

for i in range(len(lines)):
	rowname_F='F'
	index_F=5
	if lines[i].split()[index_F]!='GND':
		line=[rowname_F+lines[i].split()[0],lines[i].split()[index_F]]
		with open('fmc_row'+rowname_F+'.txt','aw') as ff:
			ff.write(' '.join(line)+'\n')

for i in range(len(lines)):
	rowname_G='G'
	index_G=4
	if lines[i].split()[index_G]!='GND':
		line=[rowname_G+lines[i].split()[0],lines[i].split()[index_G]]
		with open('fmc_row'+rowname_G+'.txt','aw') as ff:
			ff.write(' '.join(line)+'\n')

for i in range(len(lines)):
	rowname_H='H'
	index_H=3
	if lines[i].split()[index_H]!='GND':
		line=[rowname_H+lines[i].split()[0],lines[i].split()[index_H]]
		with open('fmc_row'+rowname_H+'.txt','aw') as ff:
			ff.write(' '.join(line)+'\n')

for i in range(len(lines)):
	rowname_J='J'
	index_J=2
	if lines[i].split()[index_J]!='GND':
		line=[rowname_J+lines[i].split()[0],lines[i].split()[index_J]]
		with open('fmc_row'+rowname_J+'.txt','aw') as ff:
			ff.write(' '.join(line)+'\n')

for i in range(len(lines)):
	rowname_K='K'
	index_K=1
	if lines[i].split()[index_K]!='GND':
		line=[rowname_K+lines[i].split()[0],lines[i].split()[index_K]]
		with open('fmc_row'+rowname_K+'.txt','aw') as ff:
			ff.write(' '.join(line)+'\n')

mapping=['num','K','J','H','G','F','E','D','C','B','A']
counter=0
for j in range(10,-1,-1):
	for i in range(len(lines)):
		if lines[i].split()[j]=='GND':
			counter=counter+1
			line=[mapping[j]+lines[i].split()[0],'GND_'+str(counter)]
			with open('fmc_GND'+'.txt','aw') as ff:
				ff.write(' '.join(line)+'\n')
appendix_1=['ST1','GND_ST1']
appendix_2=['ST2','GND_ST2']
with open('fmc_GND'+'.txt','aw') as ff:
	ff.write(' '.join(appendix_1)+'\n')
	ff.write(' '.join(appendix_2)+'\n')

